package com.eastfair.venueservice.service.impl;

import com.eastfair.common.api.ApplyRefundFeign;
import com.eastfair.core.base.R;
import com.eastfair.core.exception.BizException;
import com.eastfair.pay.dto.ApplyRefundDTO;
import com.eastfair.venueservice.service.VenueManageApplyRefundService;
import feign.Request;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

/**
 * 退款申请 service.
 *
 * @author dqq
 * @date 2023 /2/20
 */
@Service
@Slf4j
public class VenueManageApplyRefundServiceImpl implements VenueManageApplyRefundService {

    @Resource
    private ApplyRefundFeign applyRefundFeign;

    @Override
    public boolean acceptApplyRefund(ApplyRefundDTO applyRefundDTO) {
        log.info("acceptApplyRefund - 接受退款申请, applyRefundDTO={}", applyRefundDTO);
        Request.Options options = new Request.Options(1L, TimeUnit.MINUTES, 1L, TimeUnit.MINUTES, true);
        R result = applyRefundFeign.acceptApplyRefund(applyRefundDTO, options);
        log.info("acceptApplyRefund - 调用接受退款申请完成, applyRefundDTO={}", applyRefundDTO);
        if (!result.getIsSuccess()) {
            throw BizException.wrap(result.getCode(), result.getMsg());
        }
        return true;
    }
}